//
//  CYPayWayView.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/7/10.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYPayWayTableview.h"
#import "CYDataSourceDelegate.h"
#import "CYPayWayCell.h"
@interface CYPayWayTableview (){
    paywayBlock _myblock;
}
@property (nonatomic, strong) CYDataSource *private_datasource;
@property (nonatomic, strong) CYDelegate *private_delegate;
@property (nonatomic, strong) NSMutableArray *dataArr;
@end
@implementation CYPayWayTableview
- (instancetype)initWith:(paywayBlock)block{
    self = [super init];
    if (self) {
        _myblock = block;
        _dataArr = [self getList];
        [self setupTableview];
    }
    return self;
}

- (void)setupTableview{
    WS(self)
    _private_delegate = [[CYDelegate alloc]initWithCellHeight:AL(PT(100)) views:nil block:^(NSIndexPath *index) {
        [weakSelf selectCell:index];
    }];
    
    _private_datasource =  [[CYDataSource alloc]initWithData:_dataArr identifier:@"CYPayWayCell" block:^(id cell, id data) {
        [weakSelf bind:cell data:data];
    }];
    
    self.delegate = _private_delegate;
    self.dataSource = _private_datasource;
    [self setSeparatorInset:UIEdgeInsetsZero];
    [self setLayoutMargins:UIEdgeInsetsZero];
}

- (void)bind:(CYPayWayCell *)cell data:(NSDictionary *)dict{
    cell.title = dict[@"title"];
    cell.detailTitle = dict[@"detailTitle"];
}

- (void)selectCell:(NSIndexPath *)index{
    NSDictionary *subDic = _dataArr[index.row];
    _myblock(@{subDic[@"title"]:subDic[@"id"]});
    [self hidden];

}

- (void)hidden{
    [UIView animateWithDuration:0.3 animations:^{
        self.transform = CGAffineTransformIdentity;
    }];
    
}
- (NSMutableArray *)getList{
    NSArray *array = @[@{@"title":@"网银转账",@"detailTitle":@"登录网上银行以完成转账",@"id":@"0"},
                       @{@"title":@"ATM转账",@"detailTitle":@"到银行ATM将款项转制银行账号",@"id":@"1"},
                       @{@"title":@"ATM现存",@"detailTitle":@"到银行ATM以现金存入银行账号",@"id":@"2"},
                       @{@"title":@"银行柜台",@"detailTitle":@"到银行柜台将款项转制银行账号",@"id":@"3"},
                       @{@"title":@"手机转账",@"detailTitle":@"通过手机验证将款项转制银行账号",@"id":@"4"},
                       @{@"title":@"其他",@"detailTitle":@"其他方式",@"id":@"5"},];
    return (NSMutableArray *)array;
    
}


/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
